<template>
    <div class="home-center-right" v-if="deviceInfo.length">
        <div class="system-count">
            <img src="@/assets/image/home/device.png" />
            <div class="sensor-text">
                <span>系统当前设备接入数</span>
                <div>
                    <span>{{ deviceInfo[0].equipmentTotal || 0 }}</span>
                    <span>台</span>
                </div>
            </div>
        </div>
        <div class="title">
            <i class="iconfont icon-shebeixinxi icon"></i>
            <span>设备信息</span>
        </div>
        <div class="device-state">
            <div class="device-a">
                <span>{{ deviceInfo[0].equipmentName }}</span>
                <span>{{ deviceInfo[0].equipmentCode }}</span>
            </div>
            <div class="device-b">
                <div class="device-b-item">
                    <span>{{ deviceInfo[0].ratedLoad || 0 }}</span>
                    <span>额定载荷(t)</span>
                </div>
                <div class="device-b-item">
                    <span>{{ deviceInfo[0].height || 0 }}</span>
                    <span>高度(m)</span>
                </div>
                <div class="device-b-item">
                    <span>{{ deviceInfo[0].spanBaseDistance || 0 }}</span>
                    <span>跨度(m)</span>
                </div>
            </div>
            <div class="device-c">
                <div class="device-c-item">
                    <img src="@/assets/image/home/device.png" />
                    <div class="device-text">
                        <span>传感器数量</span>
                        <span>{{ deviceInfo[0].sensorTotal || 0 }}</span>
                    </div>
                </div>
                <div class="device-c-item">
                    <img src="@/assets/image/home/device.png" />
                    <div class="device-text">
                        <span>监测点数量</span>
                        <span>{{ deviceInfo[0].monitoringPoint || 0 }}</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="title">
            <i class="iconfont icon-gongkuangtongji icon"></i>
            <span>工况统计</span>
        </div>
        <div class="working">
            <div class="working-item">
                <span>{{ deviceInfo[1]?.cumulativeUmulativeuntimeDuration }}</span>
                <span>累计运行时长</span>
            </div>
            <div class="working-item">
                <span>{{ deviceInfo[1]?.cumulativeLoadedRest }}</span>
                <span>累计带载静置时长</span>
            </div>
            <div class="working-item">
                <span>{{ deviceInfo[1]?.cumulativeStoppage }}</span>
                <span>累计停机时长</span>
            </div>
        </div>
        <div class="table-main">
            <table>
                <thead>
                    <tr>
                        <th></th>
                        <th>最大载荷(t)</th>
                        <th>最大速度(%)</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="item in deviceInfo[2]">
                        <td>{{ item?.evaluateObject }}</td>
                        <td>{{ item?.maxLoad }}</td>
                        <td>{{ item?.maxSpeed }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>

<script setup>
import { getDeviceInfo, getDeviceTime, getDeviceTable } from "@/service/api/home.js";
import { ref } from "vue";
import { mainStore } from "@/store/main";
const store = mainStore();
const deviceInfo = ref({});
Promise.all([getDeviceInfo(store.equipment.equipmentId), getDeviceTime({ equipmentCode: store.equipment.equipmentCode }), getDeviceTable({ equipmentCode: store.equipment.equipmentCode })]).then(
    (res) => {
        deviceInfo.value = [res[0].data, res[1].data, res[2].data.slice(0, 3)];
    }
);
</script>

<style lang="scss" scoped>
.home-center-right {
    box-sizing: border-box;
    background: linear-gradient(180deg, rgba(62, 167, 222, 0) 0%, rgba(62, 167, 222, 0.1) 100%);
    .title {
        margin-top: 22px;
        height: 60px;
        line-height: 60px;
        font-size: 24px;
        border-top: 1px solid rgba(0, 101, 178, 0.5);
        border-bottom: 1px solid rgba(0, 101, 178, 0.5);
        .icon {
            font-size: 24px;
            margin: 0 15px;
        }
    }
    .device-state {
        margin: 0 auto;
        background: linear-gradient(180deg, rgba(62, 167, 222, 0) 0%, rgba(62, 167, 222, 0.1) 100%);
        box-sizing: border-box;
        padding-top: 15px;
        width: 305px;
        height: 215px;
        .device-a {
            display: flex;
            justify-content: space-around;
            align-items: center;
            margin: 0 auto;
            width: 275px;
            height: 40px;
            background: rgba(75, 166, 221, 0.15);
            span {
                &:first-of-type {
                    font-weight: 600;
                    color: #ffffff;
                }
                &:last-of-type {
                    color: #c5d8ff;
                }
            }
        }
        .device-b {
            display: flex;
            justify-content: space-around;
            align-items: center;
            width: 275px;
            margin: 0 auto;
            .device-b-item {
                display: flex;
                flex-direction: column;
                align-items: center;
                width: 92px;
                height: 80px;
                span {
                    &:first-of-type {
                        margin-top: 12px;
                        font-weight: 600;
                    }
                    &:last-of-type {
                        margin-top: 7px;
                    }
                }
            }
        }
        .device-c {
            display: flex;
            justify-content: space-around;
            margin: 0 auto;
            margin-top: 10px;
            width: 275px;
            .device-c-item {
                display: flex;
                img {
                    width: 42px;
                    height: 42px;
                }
                .device-text {
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    margin-left: 5px;
                    span {
                        &:last-of-type {
                            font-weight: 600;
                        }
                    }
                }
            }
        }
    }
    .system-count {
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        padding: 18px 0;
        width: 100%;
        height: 90px;
        background: linear-gradient(180deg, rgba(62, 167, 222, 0) 0%, rgba(62, 167, 222, 0.1) 100%);
        border-top: 1px solid #1b4661;
        img {
            width: 60px;
            height: 60px;
        }
        .sensor-text {
            margin-left: 20px;
            height: 100%;
            & > div {
                text-align: left;
                span {
                    &:first-child {
                        margin-right: 8px;
                        font-size: 36px;
                        color: #4ba6dd;
                    }
                }
            }
        }
    }
    .working {
        display: flex;
        justify-content: space-between;
        margin: 12px 0 18px 0;
        .working-item {
            display: flex;
            align-items: center;
            flex-direction: column;
            span {
                &:first-of-type {
                    font-size: 20px;
                }
                &:last-of-type {
                    margin-top: 9px;
                    font-size: 12px;
                }
            }
        }
    }
    .table-main {
        box-sizing: border-box;
        text-align: center;
        font-size: 14px;
        background: linear-gradient(180deg, rgba(62, 167, 222, 0) 0%, rgba(62, 167, 222, 0.1) 100%);
        table {
            width: 93%;
            margin: 0 auto;
            height: 100%;
            border-collapse: collapse;
            th,
            td {
                height: 30px;
            }
            tbody {
                tr {
                    &:nth-of-type(even) {
                        background: rgba(75, 166, 221, 0.15);
                    }
                }
            }
        }
    }
}
</style>
